import Split from './components/split';
import WebEditor from './components/web-editor';
import locale from './locale/index';

const components = {
    Split,
    WebEditor
};

const ZVueComponent = {
    ...components,
};

const install = function(Vue, opts = {}) {
    if (install.installed) return;
    locale.use(opts.locale);
    locale.i18n(opts.i18n);

    Object.keys(ZVueComponent).forEach(key => {
        Vue.component(key, ZVueComponent[key]);
    });

    // Vue.prototype.$ZVueComponent = {
    //     size: opts.size || '',
    //     transfer: 'transfer' in opts ? opts.transfer : '',
    //     capture: 'capture' in opts ? opts.capture : true,
    //     select: {
    //         arrow: opts.select ? opts.select.arrow ? opts.select.arrow : '' : '',
    //         customArrow: opts.select ? opts.select.customArrow ? opts.select.customArrow : '' : '',
    //         arrowSize: opts.select ? opts.select.arrowSize ? opts.select.arrowSize : '' : ''
    //     }
    // };

    // Vue.prototype.$Loading = LoadingBar;
};

// auto install
if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue);
}

const API = {
    version: process.env.VERSION, // eslint-disable-line no-undef
    locale: locale.use,
    i18n: locale.i18n,
    install,
    ...components
};

API.lang = (code) => {
    const langObject = window['ZVueComponent/locale'].default;
    if (code === langObject.i.locale) locale.use(langObject);
    else console.log(`The ${code} language pack is not loaded.`); // eslint-disable-line no-console
};

module.exports.default = module.exports = API;   // eslint-disable-line no-undef
